import {defineStore} from "pinia";


/**
 * 顶部导航栏
 * @type {StoreDefinition<"menuRecord", {record: []}, {}, {}>}
 */
export const menuRecord = defineStore("menuRecord", {
  state: () => {
    return {
      current: "",
      // 路由记录
      record: []
    }
  },
  getters: {
    GET_RECORD_CURRENT(current) {
    
    }
  },
  actions: {
    SET_CURRENT(current) {
      this.current = current;
    },
    SET_RECORD(route) {
      const params = {
        "path": route.path,
        "name": route.name,
        ...route.meta
      }
      const item = this.record.find(item => item.id === params.id);
      if (!item && params.id !== '1-1') {
        if (this.record.length >= 10) this.record.splice(0, 1)
        this.record.push(params)
      }
    },
    DEL_RECORD(route) {
      const index = this.record.findIndex(item => item.id === route.id);
      this.record.splice(index, 1)
    }
  },
  // 数据持久化存储
  persist: true,
})